<?php


namespace app\api\controller;


use app\api\validate\User;
use app\BaseController;
use app\api\business\User as userBus;
class Login extends BaseController
{
    public function index(){
        if(!$this->request->isPost()){
            return show("status.error","非法请求");
        }
        $phoneNumber = $this->request->param("phone_number","","trim");
        $code = input("param.code","","intval");
        $type = input("param.type","","intval");
        $date = [
            "phone_number" => $phoneNumber,
            "code" => $code,
            "type" => $type
        ];
        $validate = new User();
        $validateRes = $validate->scene("login")->check($date);
        if(!$validateRes){
            return show(config("status.error"),$validate->getError(),"");
        }
        $userBus = new userBus();
        try {
            $result = $userBus->login($date);
        }catch (\Exception $e){
            return show($e->getCode(),$e->getMessage());
        }

        if($result){
            return show("status.success","登录成功",$result);

        }
        return show("status.error","登录失败");
    }
}